#include <iostream>
#include <queue>

using namespace std;

typedef struct node{
    int pointNum;
    struct node *next;
}Node;

typedef struct graph{
    int pointCount;
    int lineCount;
    Node **arr;
}Graph;

Graph *graph;

Graph* init(int num){
    Graph *graph = (Graph *)malloc(sizeof(Graph));
    graph->pointCount=num;
    graph->lineCount=0;
    graph->arr = (Node **)malloc(num * sizeof(Node *));
    for (size_t i = 0; i < num; i++)
    {
        graph->arr[i] = NULL;
    }
    
    return graph;
}

Node* newNode(int num, Node *next){
    Node *node = (Node *)malloc(sizeof(Node));
    node->pointNum = num;
    node->next = next;
    return node;
}

void addLink(int node, int target)
{
    graph->arr[node] = newNode(target, graph->arr[node]);
    graph->lineCount++;
}

int graphEcho(int num, Graph *graph)
{
    for (size_t i = 0; i < num; i++)
    {
        auto p = graph->arr[i];
        cout << "index:" << i;
        while (p)
        {
            cout << " -> " << p->pointNum ;
            p = p->next;
        }
        cout << endl;
    }
}

int main(int argc, char const *argv[])
{
    graph = init(13);
    addLink(1, 2);
    addLink(1, 4);
    addLink(1, 3);
    addLink(1, 12);
    addLink(9, 12);
    addLink(9, 10);
    addLink(9, 11);
    addLink(10, 12);
    addLink(4, 5);
    addLink(2, 3);
    addLink(11, 6);
    addLink(3, 5);
    addLink(3, 7);
    addLink(3, 8);
    addLink(6, 8);
    addLink(5, 7);
    graphEcho(13, graph);    
    
    int ind[13] = { 0 };
    for (size_t i = 1; i <= 12; i++)
    {
        Node *p = graph->arr[i];
        while (p)
        {
            ind[p->pointNum]++;
            p = p->next;
        }
    }
    
    queue<int> q = queue<int>();
    for (size_t i = 1; i <= 12; i++)
    {
        if (!ind[i])
        {
            q.push(i);
        }
    }

    queue<int> output = queue<int>();
    while (!q.empty())
    {
        int crt = q.front();
        q.pop();
        output.push(crt);
        
        Node *p = graph->arr[crt];
        while (p)
        {
            ind[p->pointNum]--;
            if (!ind[p->pointNum])
            {
                q.push(p->pointNum);
            }
            p = p->next;
        }
    }
    if (output.size() != 12)
    {
        cout << "error" << endl;
        return 1;
    }

    cout << "C" << output.front();
    output.pop();
    for (size_t i = 2; i <= 12; i++)
    {
        cout << "--C" << output.front();
        output.pop();
    }

    return 0;
}
